//
//  GHSAppealViewController.m
//  penzer
//
//  Created by 还带大道 on 2018/11/14.
//  Copyright © 2018年 caiyc. All rights reserved.
//

#import "GHSAppealViewController.h"
#import "GHSAppealTableViewCell.h"
#import "GHSAppealDetailViewController.h"

@interface GHSAppealViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,weak) UIView *searchBar;
@property (nonatomic,weak) UITableView *tableView;

@end

@implementation GHSAppealViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"用户申诉";
    [self setupNavRightBtn];
    [self setupSearchBar];
    [self setupTableView];
}


- (void)setupNavRightBtn
{
    UIButton *btn_right = [[UIButton alloc] init];
    btn_right.backgroundColor = [UIColor clearColor];
    [btn_right addTarget:self action:@selector(rightBtnOnClick:) forControlEvents:UIControlEventTouchUpInside];
    [btn_right setImage:[UIImage imageNamed:@"筛选"] forState:UIControlStateNormal];
    [btn_right setImage:[UIImage imageNamed:@"筛选"] forState:UIControlStateSelected];
    [btn_right setTitle:@"筛选" forState:UIControlStateNormal];
    [btn_right setTitle:@"收起" forState:UIControlStateSelected];
    [btn_right setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn_right setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    btn_right.titleLabel.font = [UIFont systemFontOfSize:15];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn_right];
    
}


- (void)setupSearchBar
{
    UIView *searchBar = [UIView new];
    _searchBar = searchBar;
    searchBar.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:searchBar];
    [searchBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.height.mas_equalTo(60);
    }];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"搜索  (1)"] forState:UIControlStateNormal];
    [btn setTitle:@"搜索" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(onClickSearch) forControlEvents:UIControlEventTouchUpInside];
    btn.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:15];
    [btn setTitleColor:RZ_COLOR(219, 219, 219) forState:UIControlStateNormal];
    btn.layer.cornerRadius = 17.5;
    btn.layer.borderColor = RZ_COLOR_ALPHA(0, 0, 0, 0.1).CGColor;
    btn.layer.borderWidth = 1;
    [searchBar addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(35);
        make.center.equalTo(searchBar);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
    }];
    
}



- (void)setupTableView
{
    UITableView *tableView = [UITableView new];
    _tableView =tableView;
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:tableView];
    
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.searchBar.mas_bottom);
        make.left.right.bottom.equalTo(self.view);
    }];
    
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([GHSAppealTableViewCell class]) bundle:nil]  forCellReuseIdentifier:NSStringFromClass([GHSAppealTableViewCell class])];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   return 3;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 205;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    GHSAppealTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([GHSAppealTableViewCell class])];
    if(indexPath.row == 0){
        cell.appealStatus = GHSAppealStatus_Processing;
    }else if (indexPath.row == 1){
       cell.appealStatus = GHSAppealStatus_Success;
    }else{
        cell.appealStatus = GHSAppealStatus_Fail;
    }
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    GHSAppealTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    GHSAppealDetailViewController *detailVc = [[GHSAppealDetailViewController alloc] initWithAppealStatus:cell.appealStatus];
    [self.navigationController pushViewController:detailVc animated:YES];
}


#pragma mark--搜索
- (void)onClickSearch
{
    RZLog(@"onClickSearch");
}



#pragma mark--筛选
- (void)rightBtnOnClick:(UIButton *)btn
{
    btn.selected = !btn.isSelected;
    
}


#pragma mark --setter&&getter

@end
